package com.haidechizi.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: wangdejun
 * @create: 2020-04-22 12:48
 **/
public class _1394_找出数组中的幸运数 {

    public int findLucky(int[] arr) {
        int result = -1;
        Map<Integer, Integer> map = new HashMap<>(arr.length);
        for (int value : arr) {
            Integer count = map.getOrDefault(value, 0);
            count++;
            map.put(value, count);
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (entry.getKey().equals(entry.getValue())) {
                result = Math.max(entry.getKey(), result);
            }
        }
        return result;
    }
}
